<?php

/**
* @copyright   (C) 2010 iJoomla, Inc. - All rights reserved.
* @license  GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) 
* @author  iJoomla.com webmaster@ijoomla.com
* @url   http://www.ijoomla.com/licensing/
* the PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript  
* are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 
* More info at http://www.ijoomla.com/licensing/
*/

defined('_JEXEC') or die('Restricted Access');
JHtml::_('behavior.tooltip');

include(JPATH_ROOT.DS."administrator".DS."components".DS."com_surveys".DS."left.php");

$document =& JFactory::getDocument();
$document->addStyleSheet("components/com_surveys/css/survey.css");

$survey = $this->survey;
$survey_responses = $this->survey_responses;
$csv_limit = 200;
?>
<form name="adminForm" id="adminForm">
	<table cellpadding="9" cellspacing="0" border="0" width="100%" class="adminlist">
		<tr>
			<td colspan="6" align="left"><span class='sectionname'><?php echo JText::_("COM_SURVEYS_EXPORT_DATA"); ?></span></td>
		</tr>
		<tr>
			<th width="2%" align="center"><?php echo JText::_("COM_SURVEYS_ID"); ?></th>
			<th width="25%" align="left"><?php echo JText::_("COM_SURVEYS_SURVEY_NAME"); ?></th>			
			<th width="16%" align="center"><?php echo JText::_("COM_SURVEYS_SURVEY_PUBLISHED"); ?></th>
			<th width="16%" align="center"><?php echo JText::_("COM_SURVEYS_SURVEY_STATUS"); ?></th>
			<th width="16%" align="center"><?php echo JText::_("COM_SURVEYS_SURVEY_RESPONSES"); ?></th>
			<th width="25%" align="center"><?php echo JText::_("COM_SURVEYS_SURVEY_DOWNLOAD"); ?></th>			
		</tr>
		<tr>
			<td align="center"><?php echo $survey["0"]["id"]; ?></td>
			<td align="left"><?php echo $survey["0"]["title"]; ?></td>		    
			<td align="center"><?php echo JHTML::_('grid.published', $survey["0"]["published"], 0); ?></td>
			<td align="center"><?php echo $survey[0]['published'] == 1 ? "Active" : "Finished"; ?></td>
			<td align="center"><?php echo $survey_responses; ?></td>
			<td align="center"></td>
		</tr>
		<?php 
			if($survey_responses <= $csv_limit){
		?>
			<tr>
				<td align="center"></td>
				<td align="right"></td>		    
				<td align="center"></td>
				<td align="center"></td>
				<td align="center"><?php echo "1 to ".$survey_responses; ?></td>
				<td align="center"><a href="index.php?option=com_surveys&controller=export&task=export_data&survey_id=<?php echo $survey["0"]["id"]; ?>&min_limit=1&max_limit=<?php echo $survey_responses; ?>&part=1" target="_blank"><?php echo strtoupper(JText::_("COM_SURVEYS_SURVEY_DOWNLOAD")); ?></a></td>
			</tr>
		<?php		
			}
			else{
				$stop = ceil($survey_responses / $csv_limit);
				$min_limit = 1;
				$max_limit = $csv_limit;
				$part = 0;
				for($i=1; $i<=$stop; $i++){
					$part ++;
		?>
			<tr>
				<td align="center"></td>
				<td align="right"></td>		    
				<td align="center"></td>
				<td align="center"></td>
				<td align="center"><?php echo $min_limit." to ".$max_limit; ?></td>
				<td align="center"><a href="index.php?option=com_surveys&controller=export&task=export_data&survey_id=<?php echo $survey["0"]["id"]; ?>&min_limit=<?php echo $min_limit; ?>&max_limit=<?php echo $max_limit; ?>&part=<?php echo $part; ?>" target="_blank"><?php echo strtoupper(JText::_("COM_SURVEYS_SURVEY_DOWNLOAD")); ?></a></td>
			</tr>
		<?php
					$min_limit = $max_limit + 1;					
					if($survey_responses > ($min_limit-1)+$csv_limit){
						$max_limit += $csv_limit;
					}
					else{
						$max_limit = $survey_responses;
					}
				}
			}
		?>
	</table>
	
	<input type="hidden" name="option" value="com_surveys" />
	<input type="hidden" name="controller" value="export" />
	<input type="hidden" name="task" value="" />
	<?php echo JHtml::_('form.token'); ?>
</form>

</td></tr></table>
<p><center><?php echo JText::_("COM_IJOOMLA_SURVEYS_POWERED_BY") ; ?>&nbsp;<a href='http://www.ijoomla.com' target='_blank'><?php echo JText::_("COM_SURVEYS_SURVEY"); ?></a></center></p>	